﻿CREATE FUNCTION [acms].[GetPublishDate]
(
	@SiteId int,
	@SiteVersion DateTime
)
RETURNS DateTime
AS
BEGIN
	declare @tmp DateTime
	if(@SiteVersion is not null) begin
		set @SiteVersion = DateAdd(n, 1, @SiteVersion)

		select top 1 @tmp = Change
		from acms.SiteVersion_View
		where SiteId = @SiteId and Change <= @SiteVersion 
		order by Change desc
		
	end
	return @tmp
END